<template>
	<view class="page">
		<view class="body" style="padding-bottom: 100rpx;">
			<Sub-title :label="detail.title" size="36rpx" />
			<view class="left">
				<u-text :text="`来源：${detail.from}`" size="24rpx" color="#466EC5" :lines="1" margin="0 6rpx 0 0" />
				<view class="botl">
					<u-text :text="detail.createtime" size="24rpx" color="#BABABA" margin="0 14rpx 0 0" />
					<view class="" style="width: 24%;display: flex;font-size: 23rpx;">
						<u-icon name="eye" size="mini"></u-icon>
						<u-text :text="`${detail.read||0}人`" size="23rpx" color="#BABABA" margin="0 0 0 8rpx" />
					</view>
				</view>
			</view>
			<view class="" style="margin: 0 auto;text-align: center;" v-if="detail.video">
				<video :src="baseUrl+detail.video" class="image"></video>
			</view>

			<u-parse :content="detail.content" style="padding-top: 4rpx;" />
			<!-- <view class="bot" style="margin:26rpx 0;">
				<view class="bot-icon">
					<Foot :comment="detail.count" :like="detail.like" :collect="detail.collect" :type="type"
						path="/pages/home/festivalDetail" :is_like="detail.is_like" :is_collect="detail.is_collect"
						:is_id="detail.id" @like="handleLike">
					</Foot>
				</view>
			</view> -->
			<!-- 注释评论 -->
			<!-- <u--textarea v-model="msg" placeholder="请留下你的评论" count autoHeight height='140'></u--textarea>
			<view class="remarkBox">
				<view class="navItem" v-for="(i,index) in dataList" :key="index">
					<view class="" style="display: flex;align-items: center;margin-bottom: 10rpx;">
						<image :src="$imageOss(i.user_avatar)" mode="aspectFill" style="" class="image"></image>
						<text class="bot1">{{i.user_nickname}} : </text>
					</view>
					<view class="">
						<text class="bot1" style="margin-left: 10rpx;">{{i.msg}}</text>
					</view>

				</view>
				<u-loadmore :status="status" />
			</view>
			<view class="bott">
				<view class="button" style="background: #6B8BD0;" @tap.stop="toSumit"> 提交 </view>
			</view> -->
		</view>
	</view>
</template>

<script>
	import {
		newsDetail,
		comment,
		comment_list,
		visitDetail,
		collect,
		like
	} from "@/request/homeApi.js";
	import config from "@/request/baseUrl.js";
	import Foot from "@/components/footer/index";
	export default {
		components: {
			Foot
		},
		data() {
			return {
				baseUrl: config.baseUrl,
				id: '',
				detail: {},
				msg: '',
				dataList: [],
				page: 1,
				last_page: 1,
				status: "nomore",
				type: null
			};
		},
		onLoad(e) {
			this.type = e.type
			this.id = e.id
			this.getDetails(e.id);
			this.getList()
		},
		onReachBottom() {
			let that = this
			if (that.page < that.last_page) {
				that.page = that.page + 1
				that.getList()
			}
		},
		methods: {
			handleLike(v) {
				this.getDetails(v)
			},
			// 获取详情
			getDetails(id) {
				if (this.type == 1) {
					wx.setNavigationBarTitle({
						title: '汇资讯详情'
					})
					newsDetail({
						id
					}).then((res) => {
						if (res.code == 200) {
							this.detail = res.data;
						} else {
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon: 'none',
							})
						}
					});
				} else {
					wx.setNavigationBarTitle({
						title: '游林芝详情'
					})
					visitDetail({
						id
					}).then((res) => {
						if (res.code == 200) {
							this.detail = res.data;
						} else {
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon: 'none',
							})
						}
					});
				}

			},

			// 提交评论
			toSumit() {
				let that = this
				comment({
					type: that.type,
					msg: that.msg,
					type_id: that.id
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '提交成功，待审核 ！',
							duration: 1500,
							icon: 'none'
						})
						that.msg = ''
						that.getList()
					} else {
						uni.showToast({
							title: res.msg,
							duration: 1500,
							icon: 'none',
						})
					}

				})
			},

			// 获取评论列表
			getList() {
				let that = this
				comment_list({
					type: that.type,
					page: that.page,
					limit: 10,
					type_id: that.id
				}).then(res => {
					if (res.code == 200) {
						that.dataList = that.dataList.concat(res.data.list)
						that.last_page = Math.ceil(res.data.count / res.data.list.length)
						res.data.count == 0 ? that.status = 'nomore' : that.status = ''
					} else {
						uni.showToast({
							title: res.msg,
							duration: 1500,
							icon: 'none',
						})
					}

				})
			},

			// 收藏
			changeImg(type, is) {
				var that = this;
				that.operate = is == 0 ? 1 : 0
				let data = {
					table: 1,
					operate: that.operate,
					id: that.id
				}
				if (type == 'collect') {
					collect(data).then(res => {
						if (res.code == 200) {
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon: 'none'
							})
							that.getDetails(that.id)
						} else {
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon: 'none',
							})
						}
					})
				} else {
					like(data).then(res => {
						if (res.code == 200) {
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon: 'none'
							})
							that.getDetails(that.id)
						} else {
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon: 'none',
							})
						}
					})
				}

			},

		},
	};
</script>

<style lang="scss" scoped>
	.page {
		padding: 20rpx 30rpx;

		.left {
			display: flex;
			justify-content: space-between;
			padding: 20rpx 0;
			border-bottom: 2rpx solid #D9D9D9;
			margin-bottom: 10rpx;

			.botl {
				display: flex;
				width: 56%;
				text-align: right;
				align-items: center;
				justify-content: space-evenly;
			}
		}

		.bott {
			position: fixed;
			bottom: 0;
			left: 0;
			height: 110rpx;
			background: #fff;
			width: 100%;
			display: flex;
			align-items: center;
			padding: 30rpx 40rpx 40rpx;
			justify-content: space-between;
			box-shadow: 0 0 10rpx rgba(228, 228, 228, 0.5);
			box-sizing: border-box;
			z-index: 2;

			.button {
				width: 100%;
				height: 70rpx;
				padding: 0 28rpx;
				box-sizing: border-box;
				margin-left: 20rpx;
				text-align: center;
				line-height: 70rpx;
				color: #fff;
				font-size: 28rpx;
				background-color: #466EC5;
				border-radius: 10rpx;
			}
		}

		.remarkBox {
			width: 100%;
			box-sizing: border-box;
			font-size: 28rpx;
			color: #909090;

			.navItem {
				width: 98%;
				// text-align: center;
				box-sizing: border-box;
				margin: 20rpx auto;

				.image {
					width: 56rpx;
					height: 56rpx;
					border-radius: 50%;
					margin-right: 16rpx;
				}
			}
		}

		.bot {
			.bot-icon {
				color: #909090;
				display: flex;
				font-family: PingFang SC;
				font-size: 26rpx;
				font-style: normal;
				font-weight: 400;
				line-height: normal;
				justify-content: flex-end;

				.box {
					display: flex;
					align-items: center;
					margin-right: 20rpx;

					.col_icon {
						width: 24rpx !important;
						height: 24rpx !important;
						margin-right: 6rpx;
					}
				}
			}
		}
	}
</style>
